package data;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import protocal.DataPackage;
import comparator.DataMessageComparator;

public class DataMessageList {
	private List<DataPackage> dataMessages;
	
	private static DataMessageList dataMessageList;
	
	private DataMessageList(){
		dataMessages = new LinkedList<>();
	}
	
	public static DataMessageList getInstance(){
		if (dataMessageList==null) {
			synchronized (DataMessageList.class) {
				if (dataMessageList==null) {
					dataMessageList = new DataMessageList();
				}
			}
		}
		return dataMessageList;
	}
	
	@SuppressWarnings("unchecked")
	public void add(DataPackage dataMessage){
		dataMessages.add(dataMessage);
		Collections.sort(dataMessages, new DataMessageComparator());
	}
	
	public List<DataPackage>  getDataMessages(){
		return dataMessages;
	}
}
